package com.sigmazero13.gameutils;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class RenameDialog extends Dialog {
	
	public interface OnRenameListener {
		public void onRename(String origName, String newName);
	};
	
	String title;
	String origName;
	
	EditText dialogNameField;
	OnRenameListener renameListener;

	public RenameDialog(Context context, String title, OnRenameListener renameListener) {
		super(context);
		
		this.title = title;
		this.renameListener = renameListener;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.rename_dialog);
		this.setTitle(title);
		dialogNameField = (EditText)findViewById(R.id.rename_text);
		
		Button rename = (Button)findViewById(R.id.rename_apply);
		rename.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				String newName = dialogNameField.getText().toString();
				renameListener.onRename(origName, newName);
				RenameDialog.this.dismiss();
			}
		});
		
		Button cancel = (Button)findViewById(R.id.rename_cancel);
		cancel.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				RenameDialog.this.cancel();
			}
		});
	}
	
	public void setDefaultText(String text) {
		origName = text;
		dialogNameField.setText(text);
	}
	
	
}
